/*************************************************************************
> File Name: 003.c
> Author: icebear
> Mail: 3322366195@qq.com
> Created Time: 2023-07-24 15:28:51
> Description: 计算字符串空格数;
************************************************************************/

#include <stdio.h>
#include <string.h>
#define SIZE 200
int main(int argc, char const *argv[])
{
    printf("input a string\n");
    char str[SIZE] = {0};
    int length = 0;
    int span = 0;
    fgets(str, SIZE, stdin);

    char *p = str;
    while (*p++ != '\0')
    {
        length++;
        if (length > SIZE)
        {
            printf("length over bound");
            return -1;
        }
    }
    length--;
    str[length] = '\0';
    printf("the original str is: %s \norginal length is %d\n", str, length);
    p = str;
    while (*p != '\0')
    {
        if (*p == ' ')
        {
            span++;
            *p++;
            length--;
        }
        if (span == 0)
        {
            p++;
            continue;
        }
        else
        {
            *(p - span) = *p;
            p++;
        }
    }
    str[length] = '\0';
    printf("the new str is: %s \nnew length is %d\nblankspace is %d\n", str, length, span);
    return 0;
}
